//
//  BLECenter+BLEAdd.m
//  BLESDKDemo
//
//  Created by 李阳 on 2018/4/6.
//  Copyright © 2018年 李阳. All rights reserved.
//

#import "NSError+BLEAdd.h"

@interface NSError_BLEAdd : NSObject
@end
@implementation NSError_BLEAdd
@end

@implementation NSError (BLEAdd)

+ (NSError *)errorWithCode:(NSInteger)code message:(NSString *)msg {
    return [NSError errorWithDomain:@"BLESDK.Domain"
                               code:code
                           userInfo:@{NSLocalizedDescriptionKey : msg.length?msg:@""}];
}
- (NSString *)msg {
    NSString *message = self.userInfo[@"message"];
    return [message length] ? message : self.localizedDescription;
}

/// 蓝牙忙碌
+ (NSError *)bleBusyError
{
    return [self errorWithCode:BLECodeBusy message:@"Bluetooth is busy now!"];
}

/// 蓝牙超时
+ (NSError *)bleTimeoutError
{
    return [self errorWithCode:BLECodeTimeout message:@"Time out!"];
}

/// 蓝牙关闭
+ (NSError *)bleCenterDisableError
{
    return [self errorWithCode:BLECodeCenterDisable message:@"please open the bluetooth!"];
}

/// 设备断开连接
+ (NSError *)bleDeviceDisconnectError
{
    return [self errorWithCode:BLECodeDeviceDisconnect message:@"Please connect to device!"];
}

+ (NSError *)bleDeviceNotReadyError
{
    return [self errorWithCode:BLECodeDeviceNotReachable message:@"Please ready your device"];
}

+ (NSError *)bleDeviceNotFound
{
    return [self errorWithCode:BLECodeDeviceNotReachable message:@"You forgot to connect to device!"];
}

/// 数据发送错误
+ (NSError *)bleDataSendError
{
    return [self errorWithCode:BLECodeDataSendFailed message:@"Send data failed!"];
}

/// 数据响应错误
+ (NSError *)bleDataResponseError
{
    return [self errorWithCode:BLECodeDataResponseFailed message:@"response failed!"];
}

/// 数据接收错误
+ (NSError *)bleDataReceiveError
{
    return [self errorWithCode:BLECodeDataReciveFailed message:@"Receive data failed!"];
}

/// 手动取消错误
+ (NSError *)bleCancelManuallyError
{
    return [self errorWithCode:BLECodeCanceldManual message:@"Canceld!"];
}

+ (NSError *)bleFailed
{
    return [self errorWithCode:BLEFailed message:@"Failed!"];
}

@end
